<template>
    <div v-if="num>0">
        <el-badge :value="num" type="primary">
            <square-button icon="el-icon-tickets" :title="title" v-on="$listeners" v-bind="$attrs"
                           @click="showDialog"></square-button>
        </el-badge>
        <notes-list-dialog :visible.sync="visible" :list="list" @reloadList="getDocumentNotice"></notes-list-dialog>
    </div>
</template>
<script>
    import eventBus from "@/utils/eventBus";
   // import schoolSignature from "@/api/officialDocument/schoolSignature/index";
    import SquareButton from "@/components/WorkFlowsDialog/Case/SquareButton";
    import NotesListDialog from "./NotesListDialog";
    export default {
        name: "NotesListButton",
        components: {NotesListDialog, SquareButton},
        props: {
            row: {
                type: Object,
                default: function () {
                    return {}
                }
            },
            title: {
                type: String,
                default: "小纸条"
            }
        },
        data() {
            return {
                visible:false,
                num:0,
                list:[]
            }
        },
        computed: {},
        created() {
            eventBus.$on("loadNotices",index=>{
                this.getDocumentNotice()
            })
            this.getDocumentNotice()
        },
        methods: {
            setNum(num){
                this.num = num
            },
            showDialog() {
                this.visible=true
            },
            getDocumentNotice(){
              this.$store.dispatch("notes/getDocumentNode",{document:this.row.id}).then(res=>{
                this.list = res.data
                this.num = this.list.length
                this.visible=this.num>0
              })
            }
        }
    }
</script>
<style  lang="scss" scoped>
        ::v-deep .el-badge__content.is-fixed{
            top: 10px;
            right: 20px;
        }
</style>
